
settingsURL = 'https://wallboard-notifier.googlecode.com/git/images/settings.png';
keyboardURL = 'https://wallboard-notifier.googlecode.com/git/images/keyboard.jpg';
phoneURL = 'https://wallboard-notifier.googlecode.com/git/images/phone.png';
cssURL = 'https://wallboard-notifier.googlecode.com/git/mergedAlert/mergedAlert.css';



function goBabyGo(){
	console.log("goBabyGo! (merged)");
	//console.log(localStorage.mergedAlertQueues);
	if ( ! localStorage.mergedAlertQueues ) {
		console.log("hopefully about to reset");
		resetMe();
	}else {
		mergedAlertQueues = JSON.parse(localStorage.getItem('mergedAlertQueues'));
	}
	
	checkDisplayed();
	createHTML2();
	//initializeHTML();
}

function notifier(img, title, text) {
	/*
	Designed to be the single notifier function, then just change the img, title, text variables as needed.
	*/
	var havePermission = window.webkitNotifications.checkPermission();
	
	if (havePermission == 0) {
   		// 0 is PERMISSION_ALLOWED
   		var notification = window.webkitNotifications.createNotification(img,title,text);

    	notification.onclick = function () { notification.cancel();	} //clicking the notification makes it go away (may remove later)
   		
   		notification.show();
   		
   		setTimeout( function(){notification.cancel()},15000); //go away after 15 seconds
  		
  	} 
	else {
		alert("The notifier won't work as it hasn't got permission");
  	}
}  

function resetMe() {
	/*
	This thing should:
		-clear localStorage
		-initialize callQueues from the default
		-Set all HTML elements back to their default state
	*/
	console.log("resetMe");

	//set defaults for those properties
	var maxCall = 50;
	var maxWait = 60;
	var maxLong = 20;
	sliderDef = 0; //where the sliders should be set by default (0 = off)
		
	localStorage.clear();

	mergedAlertQueues = {	
	callQueues:{ 
		"support":{"pretty_name":"Support",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"level_2":{"pretty_name":"L2",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"reseller":{"pretty_name":"Reseller",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"level_3":{"pretty_name":"L3 (Dedi/VPS)",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"up":{"pretty_name":"UP",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"sales":{"pretty_name":"Sales",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"verifiers":{"pretty_name":"Verifiers",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"saves":{"pretty_name":"saves",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"tos":{"pretty_name":"ToS",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"sales_reseller":{"pretty_name":"Sales, Reseller",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"supervisors":{"pretty_name":"Supervisors",	
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"welcome":{"pretty_name":"Welcome",		
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"billing":{"pretty_name":"Billing",		
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"chargebacks":{"pretty_name":"Chargebacks",	
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"fraud":{"pretty_name":"Fraud",			
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"icann":{"pretty_name":"ICANN",			
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"jh_level_2":{"pretty_name":"JH Level 2",		
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"seo":{"pretty_name":"SEO",			
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"sales_bigsenders":{"pretty_name":"Sales, Big Senders",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},		
		
		"billing_escalations":{"pretty_name":"Billing Escalations",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"hostgator_billing":{"pretty_name":"Hostgator Billing",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"product_consultant":{"pretty_name":"Product Consultant",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"chargebacks_escalations":{	"pretty_name":"Chargebacks Escalations",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"longSlider":sliderDef,"longSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1}
		},

	chatQueues:{ 
		"support":{"pretty_name":"Support",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"l2":{"pretty_name":"L2",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},

		"reseller":{"pretty_name":"Reseller",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"l3":{"pretty_name":"L3 (Escalation)",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"sales":{"pretty_name":"Sales",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"verification":{"pretty_name":"Verifiers",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"saves":{"pretty_name":"saves",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"tos":{"pretty_name":"ToS",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"billing":{"pretty_name":"Billing",		
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"chargebacks":{"pretty_name":"Chargebacks",	
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"fraud":{"pretty_name":"Fraud",			
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"b2":{"pretty_name":"B2",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"b3":{"pretty_name":"B3",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"sitecompatibility":{"pretty_name":"Site Compat",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"qa":{"pretty_name":"QA",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"lineitems":{"pretty_name":"Lineitems",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"domains":{"pretty_name":"Domains",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"renewals":{"pretty_name":"renewals",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		
		"dedicated":{"pretty_name":"dedicated",
			"displayed":false,"is_enabled":false,"callSlider":sliderDef,"callSliderEnabled":false,"waitSlider":sliderDef,"waitSliderEnabled":false,"maxCall":maxCall,"maxWait":maxWait,"maxLong":maxLong,"timestamp":0,"timeframe":1},
		}
	}

	localStorage.mergedAlertQueues = JSON.stringify(mergedAlertQueues);
	initializeHTML();
}

function basicNotify (e,queueType) {

	if (e.target.id){ //ONLY continue IF my target ID even exists (otherwise it means it found something other than a queue)
	
	//at this point I can probably determine if it's a call or a chat then act accordingly. 
	
	//Hm, I wonder how to determine which page it is... that could be easiest but rather do it slicker than that. 

	var objectID = e.target.id.slice(6); //get a variable for my object name
	//console.log(objectID);
	//console.log(queueType);
	//console.log(mergedAlertQueues[queueType]);
	var myObject = mergedAlertQueues[queueType][objectID];

		if (myObject){ //make sure the object even exists, otherwise I don't want to continue. 

			if (myObject.displayed == true){ //make sure the object is set to display
				//console.log('displayed:',objectID); //success

				if ((Math.round(Date.now())/1000) - myObject.timestamp > 60){
					
					//The following variables need to be handled differently based on queueType
					if (queueType == 'calls'){
					var calls = parseInt(e.target.children[0].children[0].children[1].children[0].innerHTML);
					var fullWait = e.target.children[0].children[0].children[2].children[0].children[0].children[0].children[1].children[0].innerHTML;
					var wait = parseInt(fullWait.slice(0,2));
					var longs = parseInt(e.target.children[0].children[0].children[2].children[0].children[0].children[0].children[1].children[3].innerHTML);

					} else if (queueType == 'chats') {
					var calls = parseInt(e.target.children[0].children[0].children[1].children[0].innerHTML);
					var fullWait = e.target.children[0].children[0].children[2].children[0].innerHTML;
					var wait = parseInt(fullWait.slice(0,2));

					}
					

					//console.log(calls);
					if (myObject.callSliderEnabled && calls >= myObject.callSlider){ //if queue something is over a threshold then notify
						console.log('calls',objectID);
						notifyTitle = myObject.pretty_name+' queue: '+calls;
						notifyImg = phoneURL;
						notifyText = 'Wait: '+fullWait+' || Long calls: '+longs;
						notifier(notifyImg,notifyTitle,notifyText);
						myObject.timestamp = Math.round(Date.now()/1000);

					} else if (myObject.waitSliderEnabled && wait >= myObject.waitSlider) {
						console.log('wait',objectID);
						notifyTitle = myObject.pretty_name+' wait time: '+fullWait;
						notifyImg = phoneURL;
						notifyText = 'Queue: '+calls+' || Long calls: '+longs;
						notifier(notifyImg,notifyTitle,notifyText);
						myObject.timestamp = Math.round(Date.now()/1000);
						//set the title, image, message

					} else if (myObject.longSliderEnabled && longs >= myObject.longSlider) {
						console.log('longs',objectID);
						notifyTitle = myObject.pretty_name+': '+longs+' long calls';
						notifyImg = phoneURL;
						notifyText = 'Queue: '+calls+' || Wait: '+fullWait;
						notifier(notifyImg,notifyTitle,notifyText);
						myObject.timestamp = Math.round(Date.now()/1000);
						//set the title, image, message
					} 
					//notifier(notifyImg,notifyTitle,notifyText);

				}
			}
		}
	} 
}



//how to adjustThreshold for chats OR calls? Diff functions? Well, this already refers to the appropriate slider. It may be just fine. 
function adjustThreshold() {


	//have to update now for the different element (number vs slider)
	/*
	When the slider is adjusted, this will: 
		-Update the span
		-Update the object which is what the notifier relies on to determine if it needs to fire...the new challenge since I don't have an ID... Gr. 
		-Save the object to localStorage
	*/

	console.log('adjustThreshold');
	//set vars
	var objectID = this.id.slice(0,-11);
	var defineSpan = '_'+this.id.slice(-10,-6)+'SliderSpan';
	var spanID = objectID+defineSpan;
	var sliderEnabled = this.id.slice(-10,-6)+'SliderEnabled';
	var queueType = whichWallboard()+'Queues'; //Specifies which wallboard we're coming from (calls, chats... )

	//update span (I don't have one any longer, soon to remove this)
	//document.getElementById(spanID).innerHTML = this.value; 

	//update object
	paramID = this.id.slice(-10,-6)+'Slider';
	console.log(this.class);
	mergedAlertQueues[queueType][objectID][paramID] = this.value;

	//check for zeros & disable if zero is set
	if (this.value == 0){
		//say so
		console.log(spanID);
		console.log(objectID+' at zero');
		mergedAlertQueues[queueType][objectID][sliderEnabled] = false;
	} else {
		mergedAlertQueues[queueType][objectID][sliderEnabled] = true;
	}

	//save object to local storage
	localStorage.mergedAlertQueues = JSON.stringify(mergedAlertQueues);

}


function adjustStatus() {
	/*
	When the checkbox is changed, this will:
		-update the object
		-save the object to localStorage
		-possibly blur, colorize or something to a the div, feedback that it's not available / active.
		-Also maybe add new spans next to the titles of each queue on the board saying [active] or [inactive]
	*/
	objectID = this.id.slice(0,-9);
	if (this.checked == true) {
		callQueues[objectID].is_enabled = true;
	}else{
		callQueues[objectID].is_enabled = false;
	}
	localStorage.mergedAlertQueues = JSON.stringify(mergedAlertQueues);
}


function hideShow(){
	//console.log("stuff");
	var myControls = document.getElementById('controls');
	var button = document.getElementById('bfb_button')
	if (myControls.getAttribute('class') != 'hidden') {
		myControls.setAttribute('class','hidden');
		button.setAttribute('class','deselected');

	} else { 
		myControls.setAttribute('class','shown');
		button.setAttribute('class','selected');
	}
}

function addCSS(){
	var mylink = document.createElement('link');
	mylink.setAttribute("rel", "stylesheet");
	mylink.setAttribute("type", "text/css");
	mylink.setAttribute("href", cssURL);
	document.head.appendChild(mylink);
}	

function initializeHTML() {
	/*
	Sets all of my spans and sliders to their default state, need to do checkboxes too. 

	Need to adjust now because I've got calls and chats. 
	This only runs once. 

	*/
	var mySliders = document.getElementsByClassName('slider');
	//var mySpans = document.getElementsByClassName('sliderSpan');
	//var myCheckboxes = document.getElementsByClassName('checkbox');



	for (var i = 0; i < mySliders .length; i++) {

		//set sliders to whatever is in the default object.
  			
		//var objectID = mySliders[i].id.slice(0,-11);
		//var objectProperty = mySliders[i].id.slice(-10);
		//var queueType = whichWallboard()+'Queues'; //?
		//console.log(objectID,objectProperty);

		mySliders[i].value = 0;

		//mySpans[i].innerHTML = callQueues[objectID][objectProperty];
	}
	/* //old checkboxes stuff, not needing for now
	for (var i = 0; i < myCheckboxes.length; i++){
		//console.log(myCheckboxes[i]);
		myCheckboxes[i].checked = callQueues[objectID].is_enabled;
	}
	*/

}

function whichWallboard() {
	/*
	Determine just which wallboard it is that I'm working with
	I may redo this whole setup later (hate calling over and over like that, wanna avoid if I can) but for now it works
	*/
	console.log('whichWallboard'); //see when it calls

	//set vars
	var myvar = document.head.getElementsByTagName('title'); 
	
	//grab the title of each wallboard and return something simple to identify it with
	for (var i in myvar){
		
		switch(myvar[i].innerHTML)
		{
			case 'Live Chat Wallboard':
				return 'chat'; break;
				console.log('chat');
			case 'Call Wallboard':
				return 'call'; break;
				console.log('call');
		}
	}
}



function checkDisplayed() {
	/*
	Determine if the wallboard in question is displaying a particular queue or not
	I think I can reduce this to a single for loop but that would call whichWallboard a few times, I prolly don't want that. Unless I could call it once upon entering the loop and set a var...

	*/
	console.log('checkDisplayed');
	//console.log(mergedAlertQueues.callQueues[0]);


if (whichWallboard() == 'call'){
	console.log('call');
	for (var i in mergedAlertQueues.callQueues){
		//console.log('queue_'+i);
		//console.log(mergedAlertQueues.callQueues[i]);

		var displayedCallQueues = document.getElementById('queue_'+i);
		//console.log(displayedChatQueues.style.display); //freaking crap returns null, but if I do it in console it returns the div!!
		if (displayedCallQueues.style.display != 'none'){
			//console.log('yesdisplay:',displayedQueues.id)
			mergedAlertQueues.callQueues[i].displayed = true;
			//console.log(i+' displayed: '+mergedAlertQueues.callQueues[i].displayed);
		}else {
			//console.log('nodisplay:',displayedQueues.id)
			mergedAlertQueues.callQueues[i].displayed = false;
			//console.log(i+' displayed: '+mergedAlertQueues.callQueues[i].displayed);
		}

	}

}else if (whichWallboard() == 'chat') {
	console.log('chat');
	//console.log(mergedAlertQueues.chatQueues);
	for (var i in mergedAlertQueues.chatQueues){
		//console.log('queue_'+i);
		//console.log(mergedAlertQueues.chatQueues[i]);

		var displayedChatQueues = document.getElementById('queue_'+i);
		//console.log(displayedChatQueues.style.display); //freaking crap returns null, but if I do it in console it returns the div!!
		if (displayedChatQueues.style.display != 'none'){
			//console.log('yesdisplay:',displayedQueues.id)
			mergedAlertQueues.chatQueues[i].displayed = true;
			//console.log(i+' displayed: '+mergedAlertQueues.chatQueues[i].displayed);
		}else {
			//console.log('nodisplay:',displayedQueues.id)
			mergedAlertQueues.chatQueues[i].displayed = false;
			//console.log(i+' displayed: '+mergedAlertQueues.chatQueues[i].displayed);
		}

	}
}





}

function createHTML2 () {

	console.log('createHTML2');

	var bfb = document.createElement('div');
	bfb.setAttribute('id','bfb');
	//bfb.setAttribute('class','off');
	bfb.innerHTML = '<button id="bfb_button" class="off"></button>';
	bfb.addEventListener('click',hideShow);
	document.body.appendChild(bfb);

	document.getElementById("bfb_button").addEventListener("click",function() { //So that I can check for permission
		if (window.webkitNotifications.checkPermission() != 0) {
			window.webkitNotifications.requestPermission();
		} 
	});
		
	var controls = document.createElement('div');
	controls.setAttribute('id','controls');
	controls.setAttribute('class','hidden');
	document.body.appendChild(controls);
		
	//which wallboard is it? 
	var specifiedWallboard = whichWallboard();
	if (specifiedWallboard == 'call') var queueType = 'callQueues';
	else if (specifiedWallboard == 'chat') var queueType = 'chatQueues';

	//console.log(whichWallboard());



	for (var i in mergedAlertQueues[queueType]) { 
		//console.log("in for loop");
		//console.log('queueType: '+queueType);

	var queueControlDiv = document.createElement('div');
			queueControlDiv.setAttribute('id',i+'_control');
			queueControlDiv.setAttribute('class','control');

			//Create checkboxes
			/*
			var controlCheckbox = document.createElement('input');
			controlCheckbox.setAttribute('type','checkbox');
			controlCheckbox.checked=callQueues[i].is_enabled;
			controlCheckbox.setAttribute('id',i+'_checkbox'); //slap an ID on that sucker
			controlCheckbox.setAttribute('class','checkbox');
			controlCheckbox.addEventListener('click',adjustStatus);
			queueControlDiv.appendChild(controlCheckbox);
			*/

			var controlLabel = document.createElement('label');
			controlLabel.setAttribute('id',i+'_label');
			controlLabel.setAttribute('class','controlLabel');
			//controlLabel.setAttribute('class','generalLabel');
			controlLabel.innerHTML = mergedAlertQueues[queueType][i].pretty_name;
			queueControlDiv.appendChild(controlLabel);

		if (mergedAlertQueues[queueType][i].displayed == true){
			console.log(mergedAlertQueues[queueType][i].pretty_name+'.displayed true'); //runs once
			if (mergedAlertQueues[queueType][i].hasOwnProperty('callSlider')) {
				console.log('has a call slider'); 
				var rowID = i+'label';
				if (specifiedWallboard == 'call') var sliderHTML = 'Calls';
				else if (specifiedWallboard == 'chat') var sliderHTML = 'Chats';
				var max = mergedAlertQueues[queueType][i].maxCall;
				var sliderVal = mergedAlertQueues[queueType][i].callSlider;

				createRows(rowID, sliderHTML, max, sliderVal, queueControlDiv);
				document.getElementById('controls').appendChild(queueControlDiv);
				
			} 

			if (mergedAlertQueues[queueType][i].hasOwnProperty('waitSlider')) {

				console.log('has a wait slider'); 
				var rowID = i+'label';
				var sliderHTML = 'Wait Time'
				var max = mergedAlertQueues[queueType][i].maxWait;
				var sliderVal = mergedAlertQueues[queueType][i].waitSlider;

				createRows(rowID, sliderHTML, max, sliderVal, queueControlDiv);
				document.getElementById('controls').appendChild(queueControlDiv);
			}

			if (mergedAlertQueues[queueType][i].hasOwnProperty('longSlider')) {

				console.log(mergedAlertQueues[queueType][i].pretty_name+' has a long slider'); 
				var rowID = i+'label';
				var sliderHTML = 'Long Calls'
				var max = mergedAlertQueues[queueType][i].maxLong;
				var sliderVal = mergedAlertQueues[queueType][i].longSlider;

				createRows(rowID, sliderHTML, max, sliderVal, queueControlDiv);
				document.getElementById('controls').appendChild(queueControlDiv);
			}


		}
		
	}

	var resetButton = document.createElement('button');
	resetButton.setAttribute('id','resetButton');
	resetButton.innerHTML = 'reset';
	resetButton.addEventListener('click',resetMe);
	document.getElementById('controls').appendChild(resetButton);

	var wallboard = document.getElementById('wallboard');
	wallboard.addEventListener("DOMNodeInserted",function(e) {basicNotify(e,queueType)});
	
	addCSS();
}


function createRows (rowID, sliderHTML, max, sliderVal, queueControlDiv) {


	//var myQueue = specifiedWallboard+'Queues';
	//console.log('stuff:'+myQueue);

	//this needs be a separate function methinks. 
	var rowDiv = document.createElement('div');
	rowDiv.setAttribute('id',rowID); //<< need an ID
	queueControlDiv.appendChild(rowDiv);

	var rowSliderLabel = document.createElement('label');
	//rowSliderLabel.setAttribute('id',); //<< << need an ID
	rowSliderLabel.setAttribute('class','sliderLabel generalLabel');
	rowSliderLabel.innerHTML = sliderHTML; //<< Need an innerHTML
	rowDiv.appendChild(rowSliderLabel);

	var rowSlider = document.createElement('input');
	//rowSlider.setAttribute('id',); //<< Need an ID
	rowSlider.setAttribute('class','slider');
	rowSlider.setAttribute('type','number');
	rowSlider.setAttribute('min',0);
	rowSlider.setAttribute('max',max); //<< need an object property
	rowSlider.value = sliderVal; //<< need an object property
	rowSlider.setAttribute('step','1');
	rowSlider.addEventListener('change',adjustThreshold); 
	rowDiv.appendChild(rowSlider);

}




function isReady() {
	console.log("isReady()");
	if (document.getElementById('queue_support')) goBabyGo();
	else setTimeout(isReady,200);
}

	isReady();